package qr.server.admin;

import java.io.FileOutputStream;
import java.util.ArrayList;

import com.itextpdf.text.Image;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.Document;

/** 
 * New Class for exporting to pdf created, due to import
 * collision of Image classes with the Java Image class. 
 * @author shunny
 *
 */
public class ExportToPdf {
	
	public void pdfExport(String imageFilePath, String locationID) { 
		
		try { 
			
		//Get Current Directory
		String currentDirectory = System.getProperty("user.dir");
		Document newPDF = new Document();
		
		PdfWriter.getInstance(newPDF, new FileOutputStream(currentDirectory + "_" + "QR Code for Location " + locationID + ".pdf"));
		newPDF.open();
		Image qrCodeImg = Image.getInstance(imageFilePath);
		newPDF.add(new Paragraph("QR Code for Location ID: " + locationID));
		newPDF.add(qrCodeImg);
		newPDF.close(); 
		
		System.out.println("PDF of QR code has been succesfully created.");
		
		} catch (Exception exception) { 
			System.out.println("Warning! Error in PDF export of QR code." + exception);
		}
	}
	
	public void pdfExport(ArrayList<String> QrCodes) { 
		
		try { 
			
		//Get Current Directory
		String currentDirectory = System.getProperty("user.dir");
		Document newPDF = new Document();
		
		PdfWriter.getInstance(newPDF, new FileOutputStream(currentDirectory));
		newPDF.open();
		for (int i = 0; i< QrCodes.size(); i++)  {
			String imgFilePath = QrCodes.get(i);
			Image qrCodeImg = Image.getInstance(imgFilePath);
			newPDF.add(qrCodeImg);
		}
		newPDF.close(); 
		
		System.out.println("PDF of QR code has been succesfully created.");
		
		} catch (Exception exception) { 
			System.out.println("Warning! Error in PDF export of QR code.");
		}
	}
}
